package team.sun.sss.dao.hardwork;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import team.sun.sss.pojo.hardwork.HwApply;
import team.sun.sss.pojo.hardwork.HwBatch;

import java.util.Date;
import java.util.List;

@Mapper
@Repository

public interface HwApplyDao {


    //1.学工显示所有的申请表
    @Select("select * from hw_apply ")
    List<HwApply>getStuHwApplyList();
    //2.显示某个学生的申请表
    @Select("select * from hw_apply where stu_id=#{stuId} ")
    List<HwApply>getHwApplyList(int stuId);
    //2.1显示某条具体的申请
    @Select("select * from hw_apply where hwa_num=#{hwaNum} ")
   HwApply getHwApplyDetail(int hwaNum);
    //三表联立
    @Select("select student.stu_id,student.stu_name,student.stu_grade,hw_apply.*  from student,hw_apply where student.stu_id=hw_apply.stu_id")
    List<HwApply>stuApplyList();
    //根据批次、用人单位、工作状态查询
    @Select("select student.stu_id,student.stu_name,student.stu_grade,hw_apply.*  from student,hw_apply where student.stu_id=hw_apply.stu_id " +
            "and batch_team=#{batchTeam} and hwa_unit=#{unit} and hwa_work_state=#{workState}")
    List<HwApply>selectApply(String batchTeam,String unit,String workState);
    //根据学号查询
    @Select("select student.stu_id,student.stu_name,student.stu_grade,hw_apply.*  from student,hw_apply where student.stu_id=hw_apply.stu_id " +
            "and student.stu_id=#{stuId}")
    List<HwApply>selectApplyById(int stuId);
    //根据姓名查询
    @Select("select student.stu_id,student.stu_name,student.stu_grade,hw_apply.*  from student,hw_apply where student.stu_id=hw_apply.stu_id " +
            "and student.stu_name=#{stuName}")
    List<HwApply>selectApplyByName(String stuName);
    //3.学工只能修改申请表的审核状态
    @Update("update hw_apply set hwa_apply_state=#{hwaApplyState}, hwa_work_state=#{hwaWorkState} ," +
            "hwa_enter_time=#{hwaEnterTime} where hwa_num= #{hwaNum} ")
    int updateHwApply(int hwaNum,String hwaApplyState, String hwaWorkState, String hwaEnterTime);
    //4.学生提交申请表,不过学生不能更改审核状态
    @Insert("insert into hw_apply(stu_id,hwa_debt,hwa_isward,hwa_month_money,hwa_isloan,hwa_perform,hwa_unit,hwa_past_unit" +
            ",hwa_canwork_time,hwa_apply_state,hwa_work_state,hwa_submit_time,batch_team,family_level_explain) " +
            "values(#{stuId},#{hwaDebt},#{hwaIsWard},#{hwaMonthMoney},#{hwaIsLoan},#{hwaPerform},#{hwaUnit}," +
            "#{hwaPastUnit},#{hwaCanworkTime},#{hwaApplyState},#{hwaWorkState},#{hwaSubmitTime},#{batchTeam},#{familyLevelExplain})")
    int submitHwApply(int stuId, float hwaDebt, float hwaMonthMoney,
                      String hwaIsWard, String hwaIsLoan, String hwaPerform,
                      String  hwaUnit, String hwaPastUnit, String hwaCanworkTime,
                      String hwaApplyState, String hwaWorkState,
                      String hwaSubmitTime, String batchTeam,String familyLevelExplain );//AddFanMessage assFamMessage
    //5.学生撤回自己的申请表
    @Delete("delete from hw_apply where stu_id=#{stuId} and haw_num =#{hawNum}")
    int deleteHwApply( int stuId,int hawNum);
}
